<?php
/**
 * @since      File available since Release v1.1
 */

class indexControl extends BaseHomeControl{
	public function __construct(){
		parent::__construct();
        Language::read('indexs');
        Tpl::output('index_sign','index');
        
        $model = Model();
        $setting = $model->table('setting')->where(array('name'=>'guanzhu_link'))->find();
        Tpl::output('guanzhu_link',$setting['value']);
	}
	
	
	public function ajaxindexauctionOp(){
		$model = Model();		
		
		$condition = array();
		$condition['is_fabu'] = 1;
		$condition['is_state'] = '0';

		$model->table('auction')->where(array('id'=>intval($_GET['auction_id'])))->setInc('viewnum',1);
		$condition['id'] = intval($_GET['auction_id']);
	
		$auction = $model->table('auction,user')->join('left')->on('auction.seller_id = user.user_id')->where($condition)->order('auction.add_time desc')->select();

		if(!empty($auction)){
			$ulevel = $model->table('level')->where(array('type'=>'0'))->select();
			$slevel = $model->table('level')->where(array('type'=>'1'))->select();
			foreach($auction as $k=>$v){
				$like = $model->table('like')->where(array('auction_id'=>$v['id']))->order('like_add_time asc')->select();
				$auction[$k]['like'] = $like;

				$field = 'auction_log.*,user.upoints as upoints';
				$log = $model->field($field)->table('auction_log,user')->join('left')->on('auction_log.user_id = user.user_id')->where(array('auction_id'=>$v['id']))->order('add_time desc')->select();
				
				if(!empty($log)){
					foreach($log as $kk=>$vv){			
						foreach($ulevel as $vvv){
							if(($vvv['start']<$vv['upoints'])&&($vvv['end']>=$vv['upoints'])){
								$log[$kk]['level'] = $vvv['name'];
								continue;
							}
						}
					}
				}
				$auction[$k]['log'] = $log;
				$img = $model->table('auction_img')->where(array('auction_id'=>$v['id']))->order('id asc')->select();
				$auction[$k]['img'] = $img;
		
				foreach($slevel as $vvvv){
					if(($vvvv['start']<$v['spoints'])&&($vvvv['end']>=$v['spoints'])){
						$auction[$k]['level'] = $vvvv['name'];
						continue;
					}
				}
		
				$gz_condition = array();
				$gz_condition['uid'] = $_COOKIE['user_id'];
				$gz_condition['fid'] = $v['seller_id'];
		
				$guanzhu = $model->table('friend')->where($gz_condition)->find();
				if(empty($guanzhu)){
					$auction[$k]['guanzhu'] = 1;
				}
		
			}
		}

		Tpl::output('auction',$auction);
		
		$common_likenum = $model->table('setting')->where(array('name'=>'common_likenum'))->find();
		Tpl::output('common_likenum',$common_likenum['value']);
		
		$renzheng_likenum = $model->table('setting')->where(array('name'=>'renzheng_likenum'))->find();
		Tpl::output('renzheng_likenum',$renzheng_likenum['value']);
		Tpl::showpage('ajaxindexauction');
	}
	
	public function ajaxsellerauctionOp(){
		$model = Model();
		$pagesize = $this->pagesize;
		$pagenum = isset($_GET['pagenum'])?intval($_GET['pagenum']):1;
		if($pagenum == 1){
			$limit = "0,{$pagesize}";
		}else{
			$pagenum = ($pagenum-1)*$pagesize;
			$limit = "{$pagenum},{$pagesize}";
		}
		
		
		$condition = array();
		$condition['is_fabu'] = 1;
		$condition['is_state'] = '0';
		$condition['is_show'] = '0';
		$condition['seller_id'] = intval($_GET['seller_id']);
		
		$auction = $model->table('auction,user')->join('left')->on('auction.seller_id = user.user_id')->where($condition)->order('auction.add_time desc')->limit($limit)->select();
		
		if(!empty($auction)){
			$ulevel = $model->table('level')->where(array('type'=>'0'))->select();
			$slevel = $model->table('level')->where(array('type'=>'1'))->select();
			foreach($auction as $k=>$v){
				$like = $model->table('like')->where(array('auction_id'=>$v['id']))->order('like_add_time asc')->select();
				$auction[$k]['like'] = $like;
				$field = 'auction_log.*,user.upoints as upoints';
				$log = $model->field($field)->table('auction_log,user')->join('left')->on('auction_log.user_id = user.user_id')->where(array('auction_id'=>$v['id']))->order('add_time desc')->select();
				
				if(!empty($log)){
					foreach($log as $kk=>$vv){
				
						foreach($ulevel as $vvv){
							if(($vvv['start']<$vv['upoints'])&&($vvv['end']>=$vv['upoints'])){
								$log[$kk]['level'] = $vvv['name'];
								continue;
							}
						}
					}
				}
				$auction[$k]['log'] = $log;
				$img = $model->table('auction_img')->where(array('auction_id'=>$v['id']))->order('id asc')->select();
				$auction[$k]['img'] = $img;
		
				foreach($slevel as $vvvv){
					if(($vvvv['start']<$v['spoints'])&&($vvvv['end']>=$v['spoints'])){
						$auction[$k]['level'] = $vvvv['name'];
						continue;
					}
				}
		
				$gz_condition = array();
				$gz_condition['uid'] = $_COOKIE['user_id'];
				$gz_condition['fid'] = $v['seller_id'];
		
				$guanzhu = $model->table('friend')->where($gz_condition)->find();
				if(empty($guanzhu)){
					$auction[$k]['guanzhu'] = 1;
				}
		
			}
		}
		
		Tpl::output('auction',$auction);
		
		$common_likenum = $model->table('setting')->where(array('name'=>'common_likenum'))->find();
		Tpl::output('common_likenum',$common_likenum['value']);
		
		$renzheng_likenum = $model->table('setting')->where(array('name'=>'renzheng_likenum'))->find();
		Tpl::output('renzheng_likenum',$renzheng_likenum['value']);
		
		Tpl::showpage('ajaxsellerauction');
		
	}
	
	/*
	 * 拍场大厅
	 * 小熊Shop
	 */
	public function indexOp(){

		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		Tpl::output('user',$user);
		//查看单品
		if(!empty($_GET['auction_id'])){
			
			$condition = array();
			$condition['id'] = intval($_GET['auction_id']);
			$condition['is_fabu'] = 1;
			$condition['is_state'] = '0';
			$auction = $model->table('auction')->where($condition)->find();
			Tpl::output('one_auction',$auction);
		
			if($_COOKIE['user_id']!=$auction['seller_id']){
				if(empty($auction)){
					Tpl::showpage('index_xiajia');
					exit;
				}
				
				if($auction['is_show']==1){
					$p = array();
					$p['user_id'] = $_COOKIE['user_id'];
					$p['auction_id'] = $auction['id'];
				
				
					$auction_log = $model->table('auction_log')->where($p)->find();
					if(empty($auction_log)){
						Tpl::showpage('index_yincang');
						exit;
					}
				}				
			}
			
			$seller = $model->table('user')->where(array('user_id'=>$auction['seller_id']))->find();
			Tpl::output('seller',$seller);
	
			$other_condition = array();
			$other_condition['seller_id'] = $auction['seller_id'];
			$other_condition['is_fabu'] = 1;
			$other_condition['end_time'] = array('gt',time());
			$other_condition['yikoujia_end'] = '0';
			
			$other_auction = $model->table('auction')->where($other_condition)->limit('0,6')->order('id desc')->select();
			Tpl::output('other_auction',$other_auction);
			//Tpl::showpage('index_auction');
			Tpl::showpage('zsm/index_auction');
			exit;
		}
		
		//查看卖家
		if(!empty($_GET['seller_id'])){
			
			$condition = array();
			$condition['seller_id'] = intval($_GET['seller_id']);
			$condition['is_fabu'] = 1;
			$condition['is_state'] = '0';
			
			$seller = $model->table('user')->where(array('user_id'=>intval($_GET['seller_id'])))->find();
			Tpl::output('seller',$seller);
			
			$count = $model->table('auction')->where($condition)->count();
			
			Tpl::output('count',$count);
			$pagesize = $this->pagesize;
			
			if($count>$pagesize){			
				Tpl::output('haspage',1);
				Tpl::output('totalpage',ceil($count/$pagesize));
			}
			
			Tpl::showpage('index_seller');
			exit;
		}
		
		$condition = array();
		$condition['is_fabu'] = 1;
		
		$user_guanzhu = $model->table('friend')->where(array('uid'=>$_COOKIE['user_id']))->select();
		$friendslist = '';
		if(!empty($user_guanzhu)){			
			foreach($user_guanzhu as $val){
				$friendslist.=$val['fid'].',';
			}
			$friendslist = $friendslist.$_COOKIE['user_id'];
		}else{
			$friendslist = $_COOKIE['user_id'];
		}
		
		$condition['seller_id'] = array('in',$friendslist);
	
		$model = Model();
		$count = $model->table('auction')->where($condition)->count();
		
		Tpl::output('count',$count);
		$pagesize = $this->pagesize;
		
		if($count>$pagesize){			
			Tpl::output('haspage',1);
			Tpl::output('totalpage',ceil($count/$pagesize));
		}
		//Tpl::showpage('index');
		Tpl::showpage('zsm/index');
	}
	public function dqrpOp(){
		$model = Model();		
		$map['start_time']=array('elt',time());		
		$map['end_time']=array('gt',time());		
		$zc_lists= $model->table('special')->where($map)->page('20')->select();		
		foreach($zc_lists as $key=>$val){			
			$zc_pp_where['Relation_zc_id']=$zc_lists[$key]['id'];			
			$zc_pp_where['zc_sh']=2;			
			$zc_pp_where['is_state']=0;			
			$zc_pp_where['add_time']=array('neq',0);			
			$auction_count=$model->table('auction')->where($zc_pp_where)->count();			
			$zc_imgs=$model->table('auction')->where($zc_pp_where)->limit(3)->select();			
			foreach($zc_imgs as $xk=>$xv){				
				$zc_imgs[$xk]['auction_img1']=$zc_imgs[$xk]['auction_add_date']."/".$zc_imgs[$xk]['auction_img1'];				
				}			
				$zc_lists[$key]['imgs']=$zc_imgs;			
				$zc_lists[$key]['auction_num']=$auction_count;									
				$zc_cj_auction_id_arr=array();			
				$relation_auction_id_arr=$model->table('auction')->where(array('Relation_zc_id'=>$zc_lists[$key]['id']))->select();			foreach($relation_auction_id_arr as $xxk=>$xxv){				array_push($zc_cj_auction_id_arr,$relation_auction_id_arr[$xxk]['id']);			}						 $map1['auction_id']=array('in',$zc_cj_auction_id_arr);			
				$zc_cj=$model->table('auction_log')->where($map1)->count();			
				$zc_lists[$key]['cj_count']=$zc_cj; 		
        }
        Tpl::output('zc_lists',$zc_lists);
        //Tpl::showpage('dqrp_zc');
        Tpl::showpage('zsm/dqrp_zc');
    }
    public function jcyzOp(){
        $model = Model();
        $zc_lists= $model->table('special')->select();
        $current_time=time();
        $zc_id_arr=array();
        foreach($zc_lists as $key=>$val){
            if($current_time<$zc_lists[$key]['start_time'] && $zc_lists[$key]['start_time']-$current_time<=2*24*3600){
                array_push($zc_id_arr,$zc_lists[$key]['id']);
            }
        }
        $map['id']=array('in',$zc_id_arr);
        $zc_lists= $model->table('special')->where($map)->page('20')->select();
        foreach($zc_lists as $key=>$val){
            $zc_pp_where['Relation_zc_id']=$zc_lists[$key]['id'];
            $zc_pp_where['zc_sh']=2;
            $zc_pp_where['is_state']=0;
            $zc_pp_where['add_time']=array('neq',0);
            $auction_count=$model->table('auction')->where($zc_pp_where)->count();
            $zc_imgs=$model->table('auction')->where($zc_pp_where)->limit(3)->select();
            foreach($zc_imgs as $xk=>$xv){
                $zc_imgs[$xk]['auction_img1']=$zc_imgs[$xk]['auction_add_date']."/".$zc_imgs[$xk]['auction_img1'];
            }
            $zc_lists[$key]['imgs']=$zc_imgs;
            $zc_lists[$key]['auction_num']=$auction_count;
        }
        Tpl::output('zc_lists',$zc_lists);
        Tpl::output('show_page',$model->showpage());
        //Tpl::showpage('jcyz_zc');
        Tpl::showpage('zsm/jcyz_zc');
    }
    public function wqhgOp(){
        $model = Model();
        $map['end_time']=array('elt',time());
        $zc_lists= $model->table('special')->where($map)->page('20')->select();
        foreach($zc_lists as $key=>$val){
            $zc_pp_where['Relation_zc_id']=$zc_lists[$key]['id'];
            $zc_pp_where['zc_sh']=2;
            $zc_pp_where['add_time']=array('neq',0);
            $auction_count=$model->table('auction')->where($zc_pp_where)->count();
            $zc_imgs=$model->table('auction')->where($zc_pp_where)->limit(3)->select();
            foreach($zc_imgs as $xk=>$xv){
                $zc_imgs[$xk]['auction_img1']=$zc_imgs[$xk]['auction_add_date']."/".$zc_imgs[$xk]['auction_img1'];
            }
            $zc_lists[$key]['imgs']=$zc_imgs;
            $zc_lists[$key]['auction_num']=$auction_count;
            $zc_cj_auction_id_arr=array();
            $relation_auction_id_arr=$model->table('auction')->where(array('Relation_zc_id'=>$zc_lists[$key]['id']))->select();
            foreach($relation_auction_id_arr as $xxk=>$xxv){
                array_push($zc_cj_auction_id_arr,$relation_auction_id_arr[$xxk]['id']);
            }
            $map1['auction_id']=array('in',$zc_cj_auction_id_arr);
            $zc_cj=$model->table('auction_log')->where($map1)->count();
            $zc_lists[$key]['cj_count']=$zc_cj;
        }
        Tpl::output('zc_lists',$zc_lists);
        Tpl::output('show_page',$model->showpage());
        //Tpl::showpage('wqhg');
        Tpl::showpage('zsm/wqhg');
    }
        public function wqhg_auctionOp(){
            $model = Model();
            $user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
            $zc_name=$_GET['zc_name'];
            Tpl::output('zc_name',$zc_name);
            Tpl::output('user',$user);
            $zc_id=$_GET['zc_id'];
            Tpl::output('zc_id',$zc_id);
            //Tpl::showpage('wqhg_auction');
            Tpl::showpage('zsm/wqhg_auction');
        }

        public function wqhg_auction_ajaxOp(){

            $zc_id=$_GET["zc_id"];
            $model = Model();
            $pagesize = $this->pagesize;
            $pagenum = isset($_GET['pagenum'])?intval($_GET['pagenum']):1;
            if($pagenum == 1){
                $limit = "0,{$pagesize}";
            }else{
                $pagenum = ($pagenum-1)*$pagesize;
                $limit = "{$pagenum},{$pagesize}";
            }
            $condition = array();
            $condition['is_fabu'] = 1;
            $condition['is_state'] = '0';
            $condition['is_show'] = '0';
            $condition['Relation_zc_id'] =$zc_id;
            $f = array();
            $f['uid'] = $_COOKIE['user_id'];
            $friend = $model->table('friend')->where($f)->select();
            $str = $_COOKIE['user_id'].',';
            if(!empty($friend)){
                foreach($friend as $val){
                    $str.=$val['fid'].',';
                }
            }
            $str = trim($str,',');
            $auction = $model->table('auction,user')->join('left')->on('auction.seller_id = user.user_id')->where($condition)->order('auction.add_time desc')->limit($limit)->select();
            if(!empty($auction)){
                $ulevel = $model->table('level')->where(array('type'=>'0'))->select();
                $slevel = $model->table('level')->where(array('type'=>'1'))->select();
                foreach($auction as $k=>$v){
                    $like = $model->table('like')->where(array('auction_id'=>$v['id']))->order('like_add_time asc')->select();
                    $auction[$k]['like'] = $like;
                    $field = 'auction_log.*,user.upoints as upoints';
                    $log = $model->field($field)->table('auction_log,user')->join('left')->on('auction_log.user_id = user.user_id')->where(array('auction_id'=>$v['id']))->order('add_time desc')->select();
                    if(!empty($log)){
                        foreach($log as $kk=>$vv){
                            foreach($ulevel as $vvv){
                                if(($vvv['start']<$vv['upoints'])&&($vvv['end']>=$vv['upoints'])){
                                    $log[$kk]['level'] = $vvv['name'];
                                    continue;
                                }
                            }
                        }
                    }
                    $auction[$k]['log'] = $log;
                    $img = $model->table('auction_img')->where(array('auction_id'=>$v['id']))->order('id asc')->select();
                    $auction[$k]['img'] = $img;
                    foreach($slevel as $vvvv){
                        if(($vvvv['start']<$v['spoints'])&&($vvvv['end']>=$v['spoints'])){
                            $auction[$k]['level'] = $vvvv['name'];
                            continue;
                        }
                    }
                    $gz_condition = array();
                    $gz_condition['uid'] = $_COOKIE['user_id'];
                    $gz_condition['fid'] = $v['seller_id'];
                    $guanzhu = $model->table('friend')->where($gz_condition)->find();
                    if(empty($guanzhu)){
                        $auction[$k]['guanzhu'] = 1;
                    }
                }
            }
            Tpl::output('auction',$auction);
            $common_likenum = $model->table('setting')->where(array('name'=>'common_likenum'))->find();
            Tpl::output('common_likenum',$common_likenum['value']);
            $renzheng_likenum = $model->table('setting')->where(array('name'=>'renzheng_likenum'))->find();
            Tpl::output('renzheng_likenum',$renzheng_likenum['value']);
            //Tpl::showpage('auctionajax');
            Tpl::showpage('zsm/auctionajax');
        }
	
	
	public function auctionajaxOp(){
		$model = Model();
		$pagesize = $this->pagesize;
		$pagenum = isset($_GET['pagenum'])?intval($_GET['pagenum']):1;
		if($pagenum == 1){
			$limit = "0,{$pagesize}";
		}else{
			$pagenum = ($pagenum-1)*$pagesize;
			$limit = "{$pagenum},{$pagesize}";
		}
		
		
		$condition = array();
		$condition['is_fabu'] = 1;
		$condition['is_state'] = '0';
		$condition['is_show'] = '0';		$condition['Relation_zc_id'] = '0';				$condition['end_time'] = array('gt',time());		$condition['yikoujia_end']=0;		
		$f = array();
		$f['uid'] = $_COOKIE['user_id'];

		$friend = $model->table('friend')->where($f)->select();
		$str = $_COOKIE['user_id'].',';
		
		if(!empty($friend)){				
			foreach($friend as $val){
				$str.=$val['fid'].',';
			}
		}
		$str = trim($str,',');
		$condition['seller_id'] = array('in',$str);
			
		$auction = $model->table('auction,user')->join('left')->on('auction.seller_id = user.user_id')->where($condition)->order('auction.add_time desc')->limit($limit)->select();

		if(!empty($auction)){
			
			$ulevel = $model->table('level')->where(array('type'=>'0'))->select();
			$slevel = $model->table('level')->where(array('type'=>'1'))->select();
			foreach($auction as $k=>$v){
				$like = $model->table('like')->where(array('auction_id'=>$v['id']))->order('like_add_time asc')->select();
				$auction[$k]['like'] = $like;
				$field = 'auction_log.*,user.upoints as upoints';
				$log = $model->field($field)->table('auction_log,user')->join('left')->on('auction_log.user_id = user.user_id')->where(array('auction_id'=>$v['id']))->order('add_time desc')->select();
				
				if(!empty($log)){
					foreach($log as $kk=>$vv){
				
						foreach($ulevel as $vvv){
							if(($vvv['start']<$vv['upoints'])&&($vvv['end']>=$vv['upoints'])){
								$log[$kk]['level'] = $vvv['name'];
								continue;
							}
						}
					}
				}

				$auction[$k]['log'] = $log;
				
				$img = $model->table('auction_img')->where(array('auction_id'=>$v['id']))->order('id asc')->select();
				$auction[$k]['img'] = $img;

				foreach($slevel as $vvvv){
					if(($vvvv['start']<$v['spoints'])&&($vvvv['end']>=$v['spoints'])){
						$auction[$k]['level'] = $vvvv['name'];
						continue;
					}
				}
				
				$gz_condition = array();
				$gz_condition['uid'] = $_COOKIE['user_id'];
				$gz_condition['fid'] = $v['seller_id'];
				
				$guanzhu = $model->table('friend')->where($gz_condition)->find();
				if(empty($guanzhu)){
					$auction[$k]['guanzhu'] = 1;
				}
				
			}
		}

		Tpl::output('auction',$auction);

		$common_likenum = $model->table('setting')->where(array('name'=>'common_likenum'))->find();
		Tpl::output('common_likenum',$common_likenum['value']);
		
		$renzheng_likenum = $model->table('setting')->where(array('name'=>'renzheng_likenum'))->find();
		Tpl::output('renzheng_likenum',$renzheng_likenum['value']);
				
		//Tpl::showpage('auctionajax');
		Tpl::showpage('zsm/auctionajax');
	}
	public function auctionajax2Op(){		$model = Model();		$map['start_time']=array('elt',time());		$map['end_time']=array('gt',time());		$zc_lists= $model->table('special')->where($map)->page('20')->select();		foreach($zc_lists as $key=>$val){			$zc_pp_where['Relation_zc_id']=$zc_lists[$key]['id'];			$zc_pp_where['zc_sh']=2;			$zc_pp_where['add_time']=array('neq',0);			$auction_count=$model->table('auction')->where($zc_pp_where)->count();			$zc_imgs=$model->table('auction')->where($zc_pp_where)->limit(3)->select();			foreach($zc_imgs as $xk=>$xv){				$zc_imgs[$xk]['auction_img1']=$zc_imgs[$xk]['auction_add_date']."/".$zc_imgs[$xk]['auction_img1'];				}			$zc_lists[$key]['imgs']=$zc_imgs;			$zc_lists[$key]['auction_num']=$auction_count;									$zc_cj_auction_id_arr=array();			$relation_auction_id_arr=$model->table('auction')->where(array('Relation_zc_id'=>$zc_lists[$key]['id']))->select();			foreach($relation_auction_id_arr as $xxk=>$xxv){				array_push($zc_cj_auction_id_arr,$relation_auction_id_arr[$xxk]['id']);			}						 $map1['auction_id']=array('in',$zc_cj_auction_id_arr);			$zc_cj=$model->table('auction_log')->where($map1)->count();			$zc_lists[$key]['cj_count']=$zc_cj; 		}														Tpl::output('zc_lists',$zc_lists);		Tpl::showpage('auctionajax2');	}
	public function index_current_rp_auctionOp(){
	    $model = Model();
        $user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
        Tpl::output('user',$user);
        $zc_name=$_GET['zc_name'];
        $zc_id=$_GET['zc_id'];
        Tpl::output('zc_id',$zc_id);
        Tpl::output('zc_name',$zc_name);
        //Tpl::showpage('current_rp');
        Tpl::showpage('zsm/dqrp_rp');
	}
	public function jcyz_auctionOp(){
	    $zc_id=$_GET['zc_id'];
        Tpl::output('zc_id',$zc_id);
        $zc_name=$_GET['zc_name'];
        Tpl::output('zc_name',$zc_name);
        $model = Model();
        $model->table('special')->where(array('id'=>$zc_id))->setInc('wg_num',1);
        //Tpl::showpage('jcyz_auction');
        Tpl::showpage('zsm/jcyz_auction');
	}
        public
        function jcyz_auction_ajaxOp(){		$zc_id=$_GET['zc_id'];		$model = Model();		$pagesize = $this->pagesize;				$pagenum = isset($_GET['pagenum'])?intval($_GET['pagenum']):1;		if($pagenum == 1){			$limit = "0,{$pagesize}";		}else{			$pagenum = ($pagenum-1)*$pagesize;			$limit = "{$pagenum},{$pagesize}";		}						$condition = array();		$condition['is_fabu'] = 1;		$condition['is_state'] = '0';		$condition['is_show'] = '0';		$condition['Relation_zc_id'] = $zc_id;		$f = array();		$f['uid'] = $_COOKIE['user_id'];		$friend = $model->table('friend')->where($f)->select();		$str = $_COOKIE['user_id'].',';				if(!empty($friend)){							foreach($friend as $val){				$str.=$val['fid'].',';			}		}		$str = trim($str,',');							$auction = $model->table('auction,user')->join('left')->on('auction.seller_id = user.user_id')->where($condition)->order('auction.add_time desc')->limit($limit)->select();		if(!empty($auction)){						$ulevel = $model->table('level')->where(array('type'=>'0'))->select();			$slevel = $model->table('level')->where(array('type'=>'1'))->select();			foreach($auction as $k=>$v){				$like = $model->table('like')->where(array('auction_id'=>$v['id']))->order('like_add_time asc')->select();				$auction[$k]['like'] = $like;				$field = 'auction_log.*,user.upoints as upoints';				$log = $model->field($field)->table('auction_log,user')->join('left')->on('auction_log.user_id = user.user_id')->where(array('auction_id'=>$v['id']))->order('add_time desc')->select();								if(!empty($log)){					foreach($log as $kk=>$vv){										foreach($ulevel as $vvv){							if(($vvv['start']<$vv['upoints'])&&($vvv['end']>=$vv['upoints'])){								$log[$kk]['level'] = $vvv['name'];								continue;							}						}					}				}				$auction[$k]['log'] = $log;								$img = $model->table('auction_img')->where(array('auction_id'=>$v['id']))->order('id asc')->select();				$auction[$k]['img'] = $img;				foreach($slevel as $vvvv){					if(($vvvv['start']<$v['spoints'])&&($vvvv['end']>=$v['spoints'])){						$auction[$k]['level'] = $vvvv['name'];						continue;					}				}								$gz_condition = array();				$gz_condition['uid'] = $_COOKIE['user_id'];				$gz_condition['fid'] = $v['seller_id'];								$guanzhu = $model->table('friend')->where($gz_condition)->find();				if(empty($guanzhu)){					$auction[$k]['guanzhu'] = 1;				}							}		}		Tpl::output('auction',$auction);		$common_likenum = $model->table('setting')->where(array('name'=>'common_likenum'))->find();		Tpl::output('common_likenum',$common_likenum['value']);				$renzheng_likenum = $model->table('setting')->where(array('name'=>'renzheng_likenum'))->find();		Tpl::output('renzheng_likenum',$renzheng_likenum['value']);						Tpl::showpage('jcyz_auction_ajax');	}
	public function index_current_rp_auction_ajaxOp(){
	    $zc_id=$_GET['zc_id'];
        $model = Model();
        $pagesize = $this->pagesize;
        $pagenum = isset($_GET['pagenum'])?intval($_GET['pagenum']):1;
        if($pagenum == 1){
            $limit = "0,{$pagesize}";
        }else{
            $pagenum = ($pagenum-1)*$pagesize;
            $limit = "{$pagenum},{$pagesize}";
        }
        $condition = array();
        $condition['is_fabu'] = 1;
        $condition['is_state'] = '0';
        $condition['is_show'] = '0';
        $condition['Relation_zc_id'] = $zc_id;
        $f = array();
        $f['uid'] = $_COOKIE['user_id'];
        $friend = $model->table('friend')->where($f)->select();
        $str = $_COOKIE['user_id'].',';
        if(!empty($friend)){
            foreach($friend as $val){
                $str.=$val['fid'].',';
            }
        }
        $str = trim($str,',');
        $auction = $model->table('auction,user')->join('left')->on('auction.seller_id = user.user_id')->where($condition)->order('auction.add_time desc')->limit($limit)->select();
        if(!empty($auction)){
            $ulevel = $model->table('level')->where(array('type'=>'0'))->select();
            $slevel = $model->table('level')->where(array('type'=>'1'))->select();
            foreach($auction as $k=>$v){
                $like = $model->table('like')->where(array('auction_id'=>$v['id']))->order('like_add_time asc')->select();
                $auction[$k]['like'] = $like;
                $field = 'auction_log.*,user.upoints as upoints';
                $log = $model->field($field)->table('auction_log,user')->join('left')->on('auction_log.user_id = user.user_id')->where(array('auction_id'=>$v['id']))->order('add_time desc')->select();
                if(!empty($log)){
                    foreach($log as $kk=>$vv){
                        foreach($ulevel as $vvv){
                            if(($vvv['start']<$vv['upoints'])&&($vvv['end']>=$vv['upoints'])){
                                $log[$kk]['level'] = $vvv['name'];
                                continue;
                            }						}
                    }
                }
                $auction[$k]['log'] = $log;
                $img = $model->table('auction_img')->where(array('auction_id'=>$v['id']))->order('id asc')->select();
                $auction[$k]['img'] = $img;
                foreach($slevel as $vvvv){
                    if(($vvvv['start']<$v['spoints'])&&($vvvv['end']>=$v['spoints'])){
                        $auction[$k]['level'] = $vvvv['name'];
                        continue;
                    }
                }
                $gz_condition = array();
                $gz_condition['uid'] = $_COOKIE['user_id'];
                $gz_condition['fid'] = $v['seller_id'];
                $guanzhu = $model->table('friend')->where($gz_condition)->find();
                if(empty($guanzhu)){
                    $auction[$k]['guanzhu'] = 1;
                }
            }
        }
        Tpl::output('auction',$auction);
        $common_likenum = $model->table('setting')->where(array('name'=>'common_likenum'))->find();
        Tpl::output('common_likenum',$common_likenum['value']);
        $renzheng_likenum = $model->table('setting')->where(array('name'=>'renzheng_likenum'))->find();
        Tpl::output('renzheng_likenum',$renzheng_likenum['value']);
        //Tpl::showpage('index_current_rp_auction_ajax');
        Tpl::showpage('zsm/index_current_rp_auction_ajax');
	}

	
	public function likeOp(){

		$auction_id = intval($_GET['auction_id']);
		$user_id = $_COOKIE['user_id'];
		
		$model = Model();
		$user = $model->table('user')->where(array('user_id'=>$user_id))->find();
		if(empty($user)){
			echo json_encode(array('state'=>'0','error'=>'用户不存在'));exit;
		}
		
		$auction = $model->table('auction')->where(array('id'=>$auction_id))->find();
		if(empty($auction)){
			echo json_encode(array('state'=>'0','error'=>'拍卖不存在'));exit;
		}
		
		$condition = array();
		$condition['auction_id'] = $auction_id;
		$condition['user_id'] = $user_id;
		$like = $model->table('like')->where($condition)->find();
		if(!empty($like)){
			echo json_encode(array('state'=>'0','error'=>'已经添加'));exit;
		}
		
		$friend_array = array();
		$friend_array['uid'] = $user_id;
		$friend_array['fid'] = $auction['seller_id'];
		$friend = $model->table('friend')->where($friend_array)->find();
		if(empty($friend)){
			$friend_array['uname'] = $user['nickname'];
			$friend_array['fname'] = $auction['seller_name'];
			$model->table('friend')->insert($friend_array);	
		}
		
		$params = array();
		$params['auction_id'] = $auction['id'];
		$params['user_id'] = $user['user_id'];
		$params['nickname'] = $user['nickname'];
		$params['like_add_time'] = time();
		$params['avatar'] = $user['avatar'];
		
		$model->table('like')->insert($params);
		$model->table('auction')->where(array('id'=>$auction['id']))->setInc('likenum',1);
		$model->table('auction')->where(array('id'=>$auction['id']))->setInc('viewnum',1);
		
		$data = array();
		$data['user_id'] = $user['user_id'];
		$data['avatar'] = $user['avatar'];
		echo json_encode(array('state'=>'1','data'=>$data));
		exit;
	}
	
	public function checkauctionlogOp(){
		$model = Model();
			
		$auction = $model->table('auction')->where(array('id'=>$_POST['auction_id']))->find();
		$user = $model->table('user')->where(array('user_id'=>$_POST['user_id']))->find();
			
		$pingbi_array = array();
		$pingbi_array['seller_id'] = $auction['seller_id'];
		$pingbi_array['user_id'] = $_COOKIE['user_id'];
		$pingbi = $model->table('pingbi')->where($pingbi_array)->find();
		if(!empty($pingbi)){
			echo json_encode(array('state'=>'0','error'=>'您已经被该卖家屏蔽'));
			exit;
		}
		
		$friend_array = array();
		$friend_array['uid'] = $user['user_id'];
		$friend_array['fid'] = $auction['seller_id'];
		$friend = $model->table('friend')->where($friend_array)->find();
		if(empty($friend)){
			$friend_array['uname'] = $user['nickname'];
			$friend_array['fname'] = $auction['seller_name'];
			$model->table('friend')->insert($friend_array);
		}
		
		if(($auction['yikoujia']>0)&&($_POST['auction_price']>=$auction['yikoujia'])){
			$yikoujia_end = 1;
		}else{
			if($auction['auction_log_id']=='0'){					
				if($auction['firstprice']>0){
					if($_POST['auction_price']<$auction['firstprice']){
						echo json_encode(array('state'=>'0','error'=>'请大于起拍价格'));
						exit;
					}
				}else{
					if($_POST['auction_price']<$auction['addprice']){
						echo json_encode(array('state'=>'0','error'=>'请大于加价幅度'));
						exit;
					}
				}				
			}else{
				$totalprice = $auction['leadingprice']+$auction['addprice'];
				if($_POST['auction_price']<$totalprice){
					echo json_encode(array('state'=>'0','error'=>'价格大于当前价加上加价幅度'));
					exit;
				}
			}
		}

		$auction_log = $model->table('auction_log')->where(array('auction_id'=>$auction['id']))->order('id desc')->find();
		if($auction_log['user_id']==$_COOKIE['user_id']){
			echo json_encode(array('state'=>'0','error'=>'您已经处于领先状态'));
			exit;
		}
		
		$condition_log = array();
		$condition_log['auction_id'] = intval($_POST['auction_id']);
		$condition_log['user_id'] = intval($_POST['user_id']);
		$condition_log['is_cash'] = 1;
		$auction_log = $model->table('cash_log')->where($condition_log)->find();
			
		if(empty($auction_log)){//未支付保证金
			echo json_encode(array('state'=>'1'));
			exit;
		}else{		
			$params['auction_id'] = $auction['id'];
			$params['auction_price'] = $_POST['auction_price'];
			$params['add_time'] = time();
			$params['user_id'] = $user['user_id'];
			$params['nickname'] = $user['nickname'];
			$params['avatar'] = $user['avatar'];
			$res = $model->table('auction_log')->insert($params,true);
			if($res){
				$update = array();
				$update['leadingprice'] = $params['auction_price'];
				$update['auction_log_id'] = $res;
				if(($auction['yikoujia']>0)&&($_POST['auction_price']>=$auction['yikoujia'])){
					$update['yikoujia_end'] = 1;
				}
				
				if(($auction['end_time']-300)<time()){
					$update['end_time'] = $auction['end_time']+300;
				}
				
				$model->table('auction')->where(array('id'=>$auction['id']))->update($update);
				
				echo json_encode(array('state'=>2));
				exit;
			}
			exit;
		}
	}
	
	public function auctionaddcashOp(){
		
		$model = Model();
		$auction_id = intval($_GET['auction_id']);
		
		$auction = $model->table('auction')->where(array('id'=>$auction_id))->find();
		Tpl::output('auction',$auction);
	
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		Tpl::output('user',$user);
		Tpl::showpage('payment.cash');
	}
	
	public function auctionselleraddcashOp(){
		$model = Model();
		$auction_id = intval($_GET['auction_id']);
		
		$auction = $model->table('auction')->where(array('id'=>$auction_id))->find();
		Tpl::output('auction',$auction);
		
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		Tpl::output('user',$user);
		Tpl::showpage('payment.seller.cash');
	}
	
	public function auctionaddpriceOp(){
		
		if(isset($_POST)&&!empty($_POST)){
			$model = Model();
			
			$auction = $model->table('auction')->where(array('id'=>$_POST['auction_id']))->find();
			$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
			
			if($auction['seller_id']==$_COOKIE['user_id']){
				echo json_encode(array('state'=>'0','error'=>'不能竞拍自己'));
				exit;
			}
			
			if($auction['end_time']<time()){
				echo json_encode(array('state'=>'0','error'=>'拍卖已经结束'));
				exit;
			}
			
			$pingbi_array = array();
			$pingbi_array['seller_id'] = $auction['seller_id'];
			$pingbi_array['user_id'] = $_COOKIE['user_id'];
			$pingbi = $model->table('pingbi')->where($pingbi_array)->find();
			if(!empty($pingbi)){
				echo json_encode(array('state'=>'0','error'=>'您已经被该卖家屏蔽'));
				exit;
			}
			
			$friend_array = array();
			$friend_array['uid'] = $user['user_id'];
			$friend_array['fid'] = $auction['seller_id'];
			$friend = $model->table('friend')->where($friend_array)->find();
			if(empty($friend)){
				$friend_array['uname'] = $user['nickname'];
				$friend_array['fname'] = $auction['seller_name'];
				$model->table('friend')->insert($friend_array);
			}
			
			$auction_log = $model->table('auction_log')->where(array('auction_id'=>$auction['id']))->order('id desc')->find();
			if($auction_log['user_id']==$_COOKIE['user_id']){
				echo json_encode(array('state'=>'0','error'=>'您已经处于领先状态'));
				exit;
			}
			
			if(($auction['yikoujia']>0)&&($_POST['auction_price']>=$auction['yikoujia'])){
				$yikoujia_end = 1;
			}else{
				if($auction['auction_log_id']=='0'){					
					if($auction['firstprice']>0){
						if($_POST['auction_price']<$auction['firstprice']){
							echo json_encode(array('state'=>'0','error'=>'请大于起拍价格'));
							exit;
						}
					}else{
						if($_POST['auction_price']<$auction['addprice']){
							echo json_encode(array('state'=>'0','error'=>'请大于加价幅度'));
							exit;
						}
					}				
				}else{
					$totalprice = $auction['leadingprice']+$auction['addprice'];
					if($_POST['auction_price']<$totalprice){
						echo json_encode(array('state'=>'0','error'=>'价格大于当前价加上加价幅度'));
						exit;
					}
				}
			}
		
			$params['auction_id'] = $auction['id'];
			$params['auction_price'] = $_POST['auction_price'];
			$params['add_time'] = time();
			$params['user_id'] = $user['user_id'];
			$params['nickname'] = $user['nickname'];
			$params['avatar'] = $user['avatar'];
			$res = $model->table('auction_log')->insert($params,true);
			if($res){

				$update = array();
				$update['leadingprice'] = $params['auction_price'];
				$update['auction_log_id'] = $res;
				if($yikoujia_end){
					$update['yikoujia_end'] = $yikoujia_end;
				}
				
				if(($auction['end_time']-300)<time()){
					$update['end_time'] = $auction['end_time']+300;
				}
				
				$model->table('auction')->where(array('id'=>$auction['id']))->update($update);
				
				if($yikoujia_end==1){
					echo json_encode(array('state'=>1,'cashprice'=>0,'yikoujia_end'=>1));
					exit;
				}
				
				echo json_encode(array('state'=>1,'cashprice'=>0));
				exit;
				
			}
			exit;
		}
		
		$auction_id = intval($_GET['auction_id']);
		$model = Model();
		$auction = $model->table('auction')->where(array('id'=>$auction_id))->find();
		Tpl::output('auction',$auction);		
		
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		Tpl::output('user',$user);
		Tpl::showpage('auctionaddprice');
	}
	
	public function auctionaddtuisongOp(){

		$model = Model();
		$auction = $model->table('auction')->where(array('id'=>$_POST['auction_id']))->find();
		$seller = $model->table('user')->where(array('user_id'=>$auction['seller_id']))->find();
		$auction_log = $model->table('auction_log')->where(array('id'=>$auction['auction_log_id']))->find();
		$user = $model->table('user')->where(array('user_id'=>$auction_log['user_id']))->find();
		
		
		$data = array();
		$data['touser'] = $seller['openid'];
		$data['template_id'] = $this->getTemplateId(11);
		$data['url'] = BASE_SITE_URL.'/index.php?act=index&auction_id='.$auction['id'];
		$data['data']['first']['value'] = "您的拍品【{$auction_log['nickname']}】出价{$auction_log['auction_price']}元，目前领先";
		$data['data']['number']['value'] = "{$auction['auction_sn']}";
		$data['data']['name']['value'] = "{$auction['auction_description']}";
		$data['data']['remark']['value'] = '提醒：'.date("m月d日 H:i",$auction['end_time']).'拍卖结束';
		$data1 = json_encode($data);
		$res = $this->send_template_message($data1);
		
		$seller_log = array();
		$seller_log['auction_id'] = $auction['id'];
		$seller_log['uid'] = $auction['seller_id'];
		$seller_log['message'] = $data['data']['first']['value'];
		$seller_log['add_time'] = time();
		$model->table('seller_log')->insert($seller_log);
		
		
		$condition = array();
		$condition['auction_log.auction_id'] = $auction['id'];
		$field = 'auction_log.id as id,user.openid as openid';
		$on = 'auction_log.user_id = user.user_id';
		$userlist = $model->field($field)->table('auction_log,user')->join('left')->on($on)->where($condition)->select();
		
		if(!empty($userlist)){
			$arr = array();
			foreach($userlist as $vvv){
		
				if($user['openid']==$vvv['openid']){
					continue;
				}
		
				if(in_array($vvv['openid'],$arr)){
					continue;
				}
		
				$data = array();
				$data['touser'] = $vvv['openid'];
				$data['template_id'] = $this->getTemplateId(11);
				$data['url'] = BASE_SITE_URL.'/index.php?act=index&auction_id='.$auction['id'];
				$data['data']['first']['value'] = "【{$user['nickname']}】出价{$auction_log['auction_price']}元，目前领先";
				$data['data']['number']['value'] = "{$auction['auction_sn']}";
				$data['data']['name']['value'] = "{$auction['auction_description']}";
				$data['data']['remark']['value'] = '提醒：'.date("m月d日 H:i",$auction['end_time']).'拍卖结束';
				$data1 = json_encode($data);
				$this->send_template_message($data1);
				$arr[] = $vvv['openid'];
			}
		}
		
		echo json_encode(array('state'=>1));
		exit;
	}
	
	public function auctiondetailOp(){		
		$auction_id = intval($_GET['auction_id']);
		
		$model = Model();
		$auction = $model->table('auction')->where(array('id'=>$auction_id))->find();
		if(empty($auction)){
			exit;
		}
		
		$model->table('auction')->where(array('id'=>$auction['id']))->setInc('viewnum',1);
		$auction = $model->table('auction')->where(array('id'=>$auction_id))->find();	
		Tpl::output('auction',$auction);	
		
		$user = $model->table('user')->where(array('user_id'=>$_GET['user_id']))->find();
		
		Tpl::output('user',$user);
		Tpl::showpage('auctiondetail');
	}

	
	public function qunfaOp(){
		if(!empty($_POST)){
			$model = Model();			
			
			$hour = date("H");
			if($hour<7){
				echo json_encode(array('state'=>'0','error'=>'0点到7点不能群发拍品，稍后再来'));
				exit;
			}
			
			$condition = array();
			$condition['fid'] = $_COOKIE['user_id'];
			$user = $model->table('friend')->where($condition)->select();
			if(empty($user)){
				echo json_encode(array('state'=>'0','error'=>'暂时无人关注您无人关注'));
				exit;
			}
			
			$params = array();
			$params['user_id'] = $_COOKIE['user_id'];
			$params['auction_setid'] = trim($_POST['auction_all_id'],',');
			$params['add_time'] = time();
			$params['state'] = 0;
			
			$res = $model->table('qunfa')->insert($params);
			if($res){
				$condition1 = array();
				$condition1['id'] = array('in',trim($_POST['auction_all_id'],','));
				$model->table('auction')->where($condition1)->update(array('is_tuisong'=>'1'));
				$model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->setInc('qunfa_num','1');
				echo json_encode(array('state'=>1));
				exit;
			}		
		}
		
		$model = Model();
		$condition = array();
		$condition['is_fabu'] = 1;
		$condition['is_tuisong'] = '0';
		$condition['end_time'] = array('gt',time());
		$condition['seller_id'] = $_COOKIE['user_id'];
		$condition['yikoujia_end'] = '0';
		
		$list = $model->table('auction')->where($condition)->select();
		Tpl::output('list',$list);
		
		$user = $model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->find();
		
		if($user['qunfa_time']!=date("Y-m-d")){
			$params = array();
			$params['qunfa_time'] = date("Y-m-d");
			$params['qunfa_num'] = '0';
			$model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->update($params);
			
			$qunfa_num = '0';
		}else{
			$qunfa_num = $user['qunfa_num'];
		}
		
		Tpl::output('qunfa_num',(3-$qunfa_num));
		
		$danpin_link = $model->table('setting')->where(array('name'=>'danpin_link'))->find();
		Tpl::output('danpin_link',$danpin_link);
		
		$duopin_link = $model->table('setting')->where(array('name'=>'duopin_link'))->find();
		Tpl::output('duopin_link',$duopin_link);
		
		Tpl::showpage('qunfa');
	}
	
	public function shareOp(){
		$model = Model();
		$model->table('auction')->where(array('id'=>intval($_GET['auction_id'])))->update(array('is_share'=>1));
		
		echo json_encode(array('state'=>1));
		exit;
	}
	
	/*
	 * 摇一摇
	 * 小熊Shop team
	 */
	public function yaoOp(){
		$model = Model();
		$cate_id = isset($_GET['cid'])?intval($_GET['cid']):'1';
		$category = $model->table('category')->where(array('id'=>$cate_id))->find();
		Tpl::output('category',$category);
		
		$condition = array();
		$condition['auction.cate_id'] = $cate_id;
		$condition['auction.end_time'] = array('gt',time());
		$condition['auction.is_fabu'] = 1;
		$condition['auction.is_state'] = '0';
		$condition['auction.yikoujia_end'] = '0';
		$condition['user.is_company'] = '1';
		
		$auction = $model->table('auction,user')->join('left')->on('auction.seller_id = user.user_id')->where($condition)->select();
		Tpl::output('cid',$cate_id);
		
		if(count($auction)>5){
			$rand = array_rand($auction,5);
			$yao = array();
			if(!empty($rand)){
				shuffle($rand);
				foreach($rand as $val){
					$yao[] = $auction[$val];
				}
			}
			
			if(!empty($yao)){
				foreach($yao as $kk=>$vv){
					$level = array();
					$level['start'] = array('elt',$vv['spoints']);
					$level['end'] = array('gt',$vv['spoints']);
					$level['type'] = 1;
					$slevel = $model->table('level')->where($level)->find();
					$yao[$kk]['level'] = $slevel['name'];
				}
			}
		}else{
			$condition = array();
			$condition['auction.cate_id'] = $cate_id;
			$condition['auction.end_time'] = array('gt',time());
			$condition['auction.is_fabu'] = 1;
			$condition['auction.is_state'] = '0';
			$condition['auction.yikoujia_end'] = '0';
			$condition['user.is_company'] = '0';
			
			$auction_add = $model->table('auction,user')->join('left')->on('auction.seller_id = user.user_id')->where($condition)->select();
			$number = 5-count($auction);//未认证的拍品数
	
			if(!empty($auction_add)){
				if(!empty($auction)){
					$yao = array_merge($auction,$auction_add);
				}else{
					$yao = $auction_add;
				}
				
				if(count($yao)>5){
					$yao = array_slice($yao,0,5);
				}			
			}else{
				$yao = $auction;
			}
			
			if(!empty($yao)){
				foreach($yao as $kk=>$vv){
					$level = array();
					$level['start'] = array('elt',$vv['spoints']);
					$level['end'] = array('gt',$vv['spoints']);
					$level['type'] = 1;
					$slevel = $model->table('level')->where($level)->find();
					$yao[$kk]['level'] = $slevel['name'];
				}
			}
		}


		Tpl::output('list',$yao);
		
		$date = date("Y-m-d H").':00:00';
		$start_time = strtotime($date);
		$end_time = $start_time+3600;
		$yao_condition = array();
		$yao_condition['user_id'] = $_COOKIE['user_id'];
		$yao_condition['cate_id'] = $cate_id;
		$yao_condition['add_time'] = array('between',"{$start_time},{$end_time}");
		$yao_count = $model->table('yao')->where($yao_condition)->count();

		Tpl::output('yao_count',$yao_count);
		
		$categorylist = $model->table('category')->where(array('parent_id'=>'0'))->order('id asc')->select();
		Tpl::output('categorylist',$categorylist);
		
		Tpl::showpage('yao');
	}
	
	
	/*
	 * 摇一摇
	* 小熊Shop team
	*/
	public function yaolistOp(){
		
		$model = Model();
		$condition = array();
		$condition['yao.user_id'] = $_COOKIE['user_id'];
		$field = 'yao.id as id,auction.auction_add_date as auction_add_date,auction.id as auction_id,yao.add_time as add_time,auction.auction_description as auction_description,auction.auction_img1 as auction_img1,auction.end_time as end_time,auction.viewnum as viewnum,auction.leadingprice as leadingprice';
		$list = $model->field($field)->table('yao,auction')->join('left')->on('yao.auction_id = auction.id')->where($condition)->order('yao.add_time desc')->select();
		Tpl::output('list',$list);

		Tpl::showpage('yao.list');		
	}
	
	public function addyaoOp(){
		$model = Model();
		$auction = $model->table('auction')->where(array('id'=>intval($_GET['auction_id'])))->find();
		
		$params = array();
		$params['user_id'] = $_COOKIE['user_id'];
		$params['cate_id'] = $auction['cate_id'];
		$params['auction_id'] = $auction['id'];
		$params['add_time'] = time();
		
		$res = $model->table('yao')->insert($params);
		echo json_encode(array('state'=>1));
		exit;
	}
	
	public function mobileOp(){
		
		if(isset($_POST)&&!empty($_POST)){
			$params = array();	
			$params['mobile'] = $_POST['mobile'];
			$params['authcode'] = $_POST['authcode']; 
			$params['user_id'] = $_COOKIE['user_id'];
			
			$model = Model();
			$user = $model->table('user')->where($params)->find();
			
			if(!empty($user)){
				$model->table('user')->where($params)->update(array('isauth'=>1));
				echo json_encode(array('state'=>'1'));
			}else{
				echo json_encode(array('state'=>'0'));
			}
	
			exit;
		}
		
		Tpl::output('auction_id',$_GET['auction_id']);
		Tpl::showpage('mobile');
	}
	
	public function getauthcodeOp(){
		$model = Model();
		$user = $model->table('user')->where(array('mobile'=>trim($_GET['mobile']),'isauth'=>1))->find();
		if(!empty($user)){
			echo json_encode(array('state'=>'0','error'=>'手机号已经注册，请更换手机号'));
			exit;
		}
		
		$uri = BASE_SITE_URL.'/api/message/shortmessage.php';
		// 参数数组
		$data = C('shortmessage');
		$data['mobile'] = trim($_GET['mobile']);
		$data['code'] = rand(1000,9999);
		
		$params = array();
		$params['mobile'] = $data['mobile'];
		$params['authcode'] = $data['code'];
		
		
		
		
		$model->table('user')->where(array('user_id'=>$_COOKIE['user_id']))->update($params);
		
		$ch = curl_init ();
		curl_setopt ( $ch, CURLOPT_URL, $uri );
		curl_setopt ( $ch, CURLOPT_POST, 1 );
		curl_setopt ( $ch, CURLOPT_HEADER, 0 );
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
		$return = curl_exec ( $ch );
		curl_close ( $ch );
		echo json_encode(array('state'=>1));
		exit;
	}
	
	
	public function checkmobileOp(){
		
		$model = Model();
		$params = array();
		$params['mobile'] = trim($_GET['m']); 
		$params['isauth'] = 1;
		
		$info = $model->table('user')->where($params)->find();
		if(!empty($info)){
			echo json_encode(array('state'=>'1'));
		}else{
			echo json_encode(array('state'=>'0'));
		}
		exit;
	}
	
}